<?php
namespace Common\Models;
use Common\BaseModel;
class FUsersExtend extends BaseModel
{
    public $res;
    public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_users_extend');
    }


    /**
     * 保存值
     */
    public function save_columns($user_id,$column,$value){
        $FUserExtendDb = $this->findFirstByUserId($user_id);
        if(!$FUserExtendDb){
            $FUserExtendDb = new FUsersExtend();
            $FUserExtendDb->user_id = $user_id;
            $FUserExtendDb->$column = $value;
        }else{
            $FUserExtendDb->$column = $value;
        }
        if($FUserExtendDb->save()){
            return true;
        }else{
            return false;
        }
    }



    /**
     * 根据用户的rid查找用户
     */
    public function ridMappingUserId($column,array $ridArr){
        $rids = "'" . join("','", array_values($ridArr) ) . "'";
        $conditions = "{$column} in({$rids})";
        $sql = <<<EFO
SELECT e.* from f_users_extend as e
LEFT JOIN f_users as u on e.user_id = u.id
WHERE $conditions
EFO;
        $ridToUserChannel = $this->getDI()->get('dbMaster')->fetchAll($sql);
        $ridKeyToUserIdChannelIdValue=[];
        foreach($ridToUserChannel as $key=>$value){
            $ridKeyToUserIdChannelIdValue[$value[$column]]['user_id'] = $value['user_id'];
        }
        return $ridKeyToUserIdChannelIdValue;
    }

}
